package Pet.Management.service.impl;

import Pet.Management.domain.PetCareOffer;
import Pet.Management.repository.PetCareOfferRepository;
import Pet.Management.service.PetCareOfferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class PetCareOfferServiceImpl implements PetCareOfferService {

    @Autowired
    private PetCareOfferRepository petCareOfferRepository;

    @Override
    @Transactional
    public PetCareOffer createOffer(PetCareOffer offer) {
        return petCareOfferRepository.save(offer);
    }

    @Override
    @Transactional
    public PetCareOffer updateOffer(PetCareOffer offer) {
        return petCareOfferRepository.save(offer);
    }

    @Override
    @Transactional
    public void deleteOffer(Long id) {
        petCareOfferRepository.deleteById(id);
    }

    @Override
    public PetCareOffer getOfferById(Long id) {
        return petCareOfferRepository.findById(id)
                .orElseThrow(() -> new RuntimeException("Offer not found with id: " + id));
    }

    @Override
    public List<PetCareOffer> getOffersByDemandId(Long demandId) {
        return petCareOfferRepository.findByDemandId(demandId);
    }

    @Override
    public List<PetCareOffer> getOffersByAcceptorId(Long acceptorId) {
        return petCareOfferRepository.findByAcceptorId(acceptorId);
    }

    @Override
    public List<PetCareOffer> getOffersByDemandUserId(Long demandUserId) {
        return petCareOfferRepository.findByDemandUserId(demandUserId);
    }

    @Override
    public List<PetCareOffer> getOffersByStatus(String status) {
        return petCareOfferRepository.findByStatus(status);
    }

    @Override
    public List<PetCareOffer> getAllOffers() {
        return petCareOfferRepository.findAll();
    }
} 